import VueRouter from 'vue-router'

import About from '../pages/About'
import Home from '../pages/Home'
import News from '../pages/News'
import Message from '../pages/Message'
import Detail from '../pages/Detail'

const router =  new VueRouter({
    mode:'hash',
    routes:[
        {
            name:'guanyu',
            path:'/about',
            component:About,
            meta:{title:'关于'}
        },
        {
            path:'/home',
            name:'souye',
            component:Home,
            meta:{title:'主页'},
            children:[
                {
                    path:'news',
                    name:'xinwen',
                    component:News,
                    meta:{isAuth:true,title:'新闻'},
                   /*  beforeEnter(to,from,next){
                        if(to.meta.isAuth){
                            if(localStorage.getItem('school') === 'zd') {
                                next() // 放行
                            } else{
                                alert('没有权限')
                            }
                            
                        } else{
                            next() // 放行
                        }
                    } */
                },
                {
                    path:'message',
                    name:'xiaoxi',
                    component:Message,
                    meta:{isAuth:true,title:'消息'},
                    children:[
                        {
                            name:'xiangqing',
                            path:'detail',
                            //path:'detail/:id/:title',
                            component:Detail,
                            //props:true,// 只适用params方式
                            props($route){
                                return {id:$route.query.id,title:$route.query.title}
                            },
                            meta:{isAuth:true,title:'详情'},
                        },
                    ]
                },
            ]
        }
    ]
});

/* router.beforeEach((to,from,next)=>{

    if(to.meta.isAuth){
        if(localStorage.getItem('school') === 'zd') {
            next() // 放行
        } else{
            alert('没有权限')
        }
        
    } else{
        next() // 放行
    }
    
}) */

/* router.afterEach((to,from)=>{
    document.title = to.meta.title
}) */

export default router